
package com.demo.commons;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

public abstract class RedisCommond {

    private JedisPool jedisPool;

    public RedisCommond(JedisPool jedisPool) {
        this.jedisPool = jedisPool;
    }

    public void setJedisPool(JedisPool jedisPool) {
        this.jedisPool = jedisPool;
    }

    <T> T run(RedisCallback<T> redisCallback) {
        try (Jedis jedis = jedisPool.getResource()) {
            return redisCallback.doInRedis(jedis);
        }
    }

    public Jedis getNativeJedis() {
        return jedisPool.getResource();
    }

    public void close() {
        jedisPool.close();
    }
}